<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .product{
      margin-bottom: 10px;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- 1. 父组件向子组件传值 -->
    <item v-for="i in  product" :productdata="i"></item>
  </div>
  <script src="./js/vue.js"></script>
  <script>



    let item = {
      template:`
        <div class="product">
          <div>{{prodata.title}}</div>
          <div>单价:{{prodata.price}}</div>
          <button @click="num+=1">添加商品{{num}}</button>
        </div>
      `,
      data(){
        return{
          num:0,
          //3. 将传递进来的值赋值给一个新的属性
          prodata:this.productdata
        }
      },
      // 2. 接受父组件传递进来的值
      props:['productdata'],
      
    }
    const app =new Vue({
      el:"#app",
      data:function(){
        return{
          product:[
            {title:'商品一',price:10,num:0},
            {title:'商品二',price:15,num:0},
            {title:'商品三',price:20,num:0},
          ]
        }
      },
      components:{
        'item':item
      }
    })
  </script>
</body>
</html>